package easyjava.function;

import static easyjava.function.CastFunction.castToObject;

import java.io.Console;

/**
 * 输入输出相关方法
 *
 */
public interface IOFunction {
	
	static String input(){
        return input("");
    }

    static String input(String format,Object... args){
        Console console = System.console();
        if(console != null) {
        	return console.readLine(format,args);
        }
        throw new NullPointerException("Console not found!");
    }

    static void print(Object obj) {
    	if(obj.getClass().isArray()) {
    		StringBuilder strBuilder=new StringBuilder();
    		Object[] arr = castToObject(obj);
    		for(Object item:arr) {
    			strBuilder.append(item).append(' ');
    		}
    		System.out.print(strBuilder.toString().trim());
    	}else {
    		System.out.print(obj);
    	}
    }
    
    static void println(Object obj) {
    	if(obj.getClass().isArray()) {
    		StringBuilder strBuilder=new StringBuilder();
    		Object[] arr = castToObject(obj);
    		for(Object item:arr) {
    			strBuilder.append(item).append(' ');
    		}
    		System.out.println(strBuilder.toString().trim());
    	}else {
    		System.out.println(obj);
    	}
    }
    
    static void printf(String format,Object... args) {
        System.out.printf(format, args);
    }
}
